package com.primb.bench.project.home.model;

import android.text.TextUtils;

import com.primb.bench.common.module.http.service.ApiClient;
import com.primb.bench.common.module.http.service.ApiService;
import com.primb.bench.project.home.contract.LoanPromiseContract;
import com.primb.bench.project.home.entity.PromiseListEntity;
import com.primb.bench.project.home.entity.RequestClientEntity;
import com.primb.netlibs.converter.RxSchedulerUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Objects;

import rx.Observable;
import rx.functions.Func1;

/**
 * Created by Administrator on 2017/07/10
 */

public class LoanPromiseModelImpl implements LoanPromiseContract.Model {

    @Override
    public Observable<List<PromiseListEntity.DataBean>> getPromiseInfo(RequestClientEntity entity) {
        HashMap<String, String> map = new HashMap<>();
        map.put("start", entity.getStart() + "");
        map.put("limit", entity.getLimit() + "");

        if (entity.getCustId() != null && !TextUtils.isEmpty(entity.getCustId())) {
            map.put("custId", entity.getCustId());
        }
        return ApiClient.initService(ApiService.class).getPromiseList(map).flatMap(new Func1<PromiseListEntity, Observable<List<PromiseListEntity.DataBean>>>() {
            @Override
            public Observable<List<PromiseListEntity.DataBean>> call(PromiseListEntity promiseListEntity) {
                return Observable.just(promiseListEntity.getData());
            }
        }).compose(RxSchedulerUtils.normalSchedulersTransformer());
    }
}